home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / run-mozilla.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2006-05-08  |  10KB  |  427 lines

  1. #!/bin/sh
  2. #
  3. # ***** BEGIN LICENSE BLOCK *****
  4. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. #
  6. # The contents of this file are subject to the Mozilla Public License Version
  7. # 1.1 (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. # http://www.mozilla.org/MPL/
  10. #
  11. # Software distributed under the License is distributed on an "AS IS" basis,
  12. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. # for the specific language governing rights and limitations under the
  14. # License.
  15. #
  16. # The Original Code is mozilla.org code.
  17. #
  18. # The Initial Developer of the Original Code is
  19. # Netscape Communications Corporation.
  20. # Portions created by the Initial Developer are Copyright (C) 1998
  21. # the Initial Developer. All Rights Reserved.
  22. #
  23. # Contributor(s):
  24. #
  25. # Alternatively, the contents of this file may be used under the terms of
  26. # either of the GNU General Public License Version 2 or later (the "GPL"),
  27. # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. # in which case the provisions of the GPL or the LGPL are applicable instead
  29. # of those above. If you wish to allow use of your version of this file only
  30. # under the terms of either the GPL or the LGPL, and not to allow others to
  31. # use your version of this file under the terms of the MPL, indicate your
  32. # decision by deleting the provisions above and replace them with the notice
  33. # and other provisions required by the GPL or the LGPL. If you do not delete
  34. # the provisions above, a recipient may use your version of this file under
  35. # the terms of any one of the MPL, the GPL or the LGPL.
  36. #
  37. # ***** END LICENSE BLOCK *****
  38. cmdname=`basename "$0"`
  39. MOZ_DIST_BIN=`dirname "$0"`
  40. MOZ_DEFAULT_NAME="./${cmdname}-bin"
  41. MOZ_APPRUNNER_NAME="./mozilla-bin"
  42. MOZ_VIEWER_NAME="./viewer"
  43. MOZ_PROGRAM=""
  44.  
  45. exitcode=0
  46. #
  47. ##
  48. ## Functions
  49. ##
  50. ##########################################################################
  51. moz_usage()
  52. {
  53. echo "Usage:  ${cmdname} [options] [program]"
  54. echo ""
  55. echo "  options:"
  56. echo ""
  57. echo "    -g                   Run in debugger."
  58. echo "    --debug"
  59. echo ""
  60. echo "    -d debugger          Debugger to use."
  61. echo "    --debugger debugger"
  62. echo ""
  63. echo "  Examples:"
  64. echo ""
  65. echo "  Run the viewer"
  66. echo ""
  67. echo "    ${cmdname} viewer"
  68. echo ""
  69. echo "  Run the mozilla-bin binary"
  70. echo ""
  71. echo "    ${cmdname} mozilla-bin"
  72. echo ""
  73. echo "  Debug the viewer in a debugger"
  74. echo ""
  75. echo "    ${cmdname} -g viewer"
  76. echo ""
  77. echo "  Debug the mozilla-bin binary in gdb"
  78. echo ""
  79. echo "    ${cmdname} -g mozilla-bin -d gdb"
  80. echo ""
  81.     return 0
  82. }
  83. ##########################################################################
  84. moz_bail()
  85. {
  86.     message=$1
  87.     echo
  88.     echo "$cmdname: $message"
  89.     echo
  90.     exit 1
  91. }
  92. ##########################################################################
  93. moz_test_binary()
  94. {
  95.     binary=$1
  96.     if [ -f "$binary" ]
  97.     then
  98.         if [ -x "$binary" ]
  99.         then
  100.             return 1
  101.         fi
  102.     fi
  103.     return 0
  104. }
  105. ##########################################################################
  106. moz_get_debugger()
  107. {
  108.     debuggers="ddd gdb dbx bdb"
  109.     debugger="notfound"
  110.     done="no"
  111.     for d in $debuggers
  112.     do
  113.         moz_test_binary /bin/type
  114.         if [ $? -eq 1 ]
  115.         then
  116.             dpath=`type ${d} | awk '{print $3;}' | sed -e 's/\.$//'`    
  117.         else     
  118.             dpath=`which ${d}`    
  119.         fi
  120.         if [ -x "$dpath" ]
  121.         then
  122.             debugger=$dpath
  123.             break
  124.         fi
  125.     done
  126.     echo $debugger
  127.     return 0
  128. }
  129. ##########################################################################
  130. moz_run_program()
  131. {
  132.     prog=$MOZ_PROGRAM
  133.     ##
  134.     ## Make sure the program is executable
  135.     ##
  136.     if [ ! -x "$prog" ]
  137.     then
  138.         moz_bail "Cannot execute $prog."
  139.     fi
  140.     ##
  141.     ## Use md5sum to crc a core file.  If md5sum is not found on the system,
  142.     ## then dont debug core files.
  143.     ##
  144.     moz_test_binary /bin/type
  145.     if [ $? -eq 1 ]
  146.     then
  147.         crc_prog=`type md5sum 2>/dev/null | awk '{print $3;}' 2>/dev/null | sed -e 's/\.$//'`
  148.     else
  149.         crc_prog=`which md5sum 2>/dev/null`
  150.     fi
  151.     if [ -x "$crc_prog" ]
  152.     then
  153.         DEBUG_CORE_FILES=1
  154.     fi
  155.     if [ "$DEBUG_CORE_FILES" ]
  156.     then
  157.         crc_old=
  158.         if [ -f core ]
  159.         then
  160.             crc_old=`$crc_prog core | awk '{print $1;}' `
  161.         fi
  162.     fi
  163.     ##
  164.     ## Run the program
  165.     ##
  166.     "$prog" ${1+"$@"}
  167.     exitcode=$?
  168.     if [ "$DEBUG_CORE_FILES" ]
  169.     then
  170.         if [ -f core ]
  171.         then
  172.             crc_new=`$crc_prog core | awk '{print $1;}' `
  173.         fi
  174.     fi
  175.     if [ "$crc_old" != "$crc_new" ]
  176.     then
  177.         printf "\n\nOh no!  %s just dumped a core file.\n\n" $prog
  178.         printf "Do you want to debug this ? "
  179.         printf "You need a lot of memory for this, so watch out ? [y/n] "
  180.         read ans
  181.         if [ "$ans" = "y" ]
  182.         then
  183.             debugger=`moz_get_debugger`
  184.             if [ -x "$debugger" ]
  185.             then
  186.                 echo "$debugger $prog core"
  187.  
  188.                 # See http://www.mozilla.org/unix/debugging-faq.html
  189.                 # For why LD_BIND_NOW is needed
  190.                 LD_BIND_NOW=1; export LD_BIND_NOW
  191.  
  192.                 $debugger "$prog" core
  193.             else
  194.                 echo "Could not find a debugger on your system."
  195.             fi
  196.         fi
  197.     fi
  198. }
  199. ##########################################################################
  200. moz_debug_program()
  201. {
  202.     prog=$MOZ_PROGRAM
  203.     ##
  204.     ## Make sure the program is executable
  205.     ##
  206.     if [ ! -x "$prog" ]
  207.     then
  208.         moz_bail "Cannot execute $prog."
  209.     fi
  210.     if [ -n "$moz_debugger" ]
  211.     then
  212.         moz_test_binary /bin/type
  213.         if [ $? -eq 1 ]
  214.         then    
  215.             debugger=`type $moz_debugger | awk '{print $3;}' | sed -e 's/\.$//'` 
  216.         else
  217.             debugger=`which $moz_debugger` 
  218.         fi    
  219.     else
  220.         debugger=`moz_get_debugger`
  221.     fi
  222.     if [ -x "$debugger" ] 
  223.     then
  224.         tmpfile=`mktemp /tmp/mozargs.XXXXXX` || { echo "Cannot create temporary file" >&2; exit 1; }
  225.     trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15
  226.         echo "set args ${1+"$@"}" > $tmpfile
  227. # If you are not using ddd, gdb and know of a way to convey the arguments 
  228. # over to the prog then add that here- Gagan Saksena 03/15/00
  229.         case `basename $debugger` in
  230.             gdb) echo "$debugger $prog -x $tmpfile"
  231.                 $debugger "$prog" -x $tmpfile
  232.         exitcode=$?
  233.                 ;;
  234.             ddd) echo "$debugger --debugger \"gdb -x $tmpfile\" $prog"
  235.                 $debugger --debugger "gdb -x $tmpfile" "$prog"
  236.         exitcode=$?
  237.                 ;;
  238.             *) echo "$debugger $prog ${1+"$@"}"
  239.                 $debugger "$prog" ${1+"$@"}
  240.         exitcode=$?
  241.                 ;;
  242.         esac
  243.     else
  244.         echo "Could not find a debugger on your system." 
  245.     fi
  246. }
  247. ##########################################################################
  248. ##
  249. ## Command line arg defaults
  250. ##
  251. moz_debug=0
  252. moz_debugger=""
  253. #
  254. ##
  255. ## Parse the command line
  256. ##
  257. while [ $# -gt 0 ]
  258. do
  259.   case $1 in
  260.     -g | --debug)
  261.       moz_debug=1
  262.       shift
  263.       ;;
  264.     -d | --debugger)
  265.       moz_debugger=$2;
  266.       if [ "${moz_debugger}" != "" ]; then
  267.     shift 2
  268.       else
  269.         echo "-d requires an argument"
  270.         exit 1
  271.       fi
  272.       ;;
  273.     *)
  274.       break;
  275.       ;;
  276.   esac
  277. done
  278. #
  279. ##
  280. ## Program name given in $1
  281. ##
  282. if [ $# -gt 0 ]
  283. then
  284.     MOZ_PROGRAM=$1
  285.     shift
  286. fi
  287. ##
  288. ## Program not given, try to guess a default
  289. ##
  290. if [ -z "$MOZ_PROGRAM" ]
  291. then
  292.     ##
  293.     ## Try this script's name with '-bin' appended
  294.     ##
  295.     if [ -x "$MOZ_DEFAULT_NAME" ]
  296.     then
  297.         MOZ_PROGRAM=$MOZ_DEFAULT_NAME
  298.     ## Try viewer (this should be deprecated)
  299.     ## 
  300.     elif [ -x "$MOZ_VIEWER_NAME" ]
  301.     then
  302.         MOZ_PROGRAM=$MOZ_VIEWER_NAME
  303.     ##
  304.     ## Try mozilla-bin
  305.     ## 
  306.     elif [ -x "$MOZ_APPRUNNER_NAME" ]
  307.     then
  308.         MOZ_PROGRAM=$MOZ_APPRUNNER_NAME
  309.     fi
  310. fi
  311. #
  312. #
  313. ##
  314. ## Make sure the program is executable
  315. ##
  316. if [ ! -x "$MOZ_PROGRAM" ]
  317. then
  318.     moz_bail "Cannot execute $MOZ_PROGRAM."
  319. fi
  320. #
  321. ##
  322. ## Set MOZILLA_FIVE_HOME
  323. ##
  324. MOZILLA_FIVE_HOME=$MOZ_DIST_BIN
  325.  
  326. if [ -z "$MRE_HOME" ]; then
  327.     MRE_HOME=$MOZILLA_FIVE_HOME
  328. fi
  329. ##
  330. ## Set LD_LIBRARY_PATH
  331. LD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH+":$LD_LIBRARY_PATH"}
  332. if [ -n "$LD_LIBRARYN32_PATH" ]
  333. then
  334.     LD_LIBRARYN32_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN32_PATH+":$LD_LIBRARYN32_PATH"}
  335. fi
  336. if [ -n "$LD_LIBRARYN64_PATH" ]
  337. then
  338.     LD_LIBRARYN64_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN64_PATH+":$LD_LIBRARYN64_PATH"}
  339. fi
  340. if [ -n "$LD_LIBRARY_PATH_64" ]; then
  341.     LD_LIBRARY_PATH_64=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH_64+":$LD_LIBRARY_PATH_64"}
  342. fi
  343. #
  344. #
  345. ## Set SHLIB_PATH for HPUX
  346. SHLIB_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${SHLIB_PATH+":$SHLIB_PATH"}
  347. #
  348. ## Set LIBPATH for AIX
  349. LIBPATH=${MOZ_DIST_BIN}:${MRE_HOME}${LIBPATH+":$LIBPATH"}
  350. #
  351. ## Set DYLD_LIBRARY_PATH for Mac OS X (Darwin)
  352. DYLD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${DYLD_LIBRARY_PATH+":$DYLD_LIBRARY_PATH"}
  353. #
  354. ## Set LIBRARY_PATH for BeOS
  355. LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/components:${MRE_HOME}${LIBRARY_PATH+":$LIBRARY_PATH"}
  356. #
  357. ## Set ADDON_PATH for BeOS
  358. ADDON_PATH=${MOZ_DIST_BIN}${ADDON_PATH+":$ADDON_PATH"}
  359. #
  360. ## Solaris Xserver(Xsun) tuning - use shared memory transport if available
  361. if [ "$XSUNTRANSPORT" = "" ]
  362. then 
  363.         XSUNTRANSPORT="shmem" 
  364.         XSUNSMESIZE="512"
  365.         export XSUNTRANSPORT XSUNSMESIZE
  366. fi
  367. ## Populate XPSERVERLIST if it was not set yet
  368. if [ "$XPSERVERLIST" = "" ]
  369. then
  370.     if [ -f /etc/init.d/xprint ] ; then
  371.         XPSERVERLIST="`/bin/sh /etc/init.d/xprint get_xpserverlist`"
  372.         if [ "$XPSERVERLIST" != "" ] ; then
  373.             export XPSERVERLIST
  374.         fi
  375.     fi
  376. fi
  377.  
  378. if [ "$moz_debug" -eq 1 ]
  379. then
  380.   echo "MOZILLA_FIVE_HOME=$MOZILLA_FIVE_HOME"
  381.   echo "  LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
  382.   if [ -n "$LD_LIBRARYN32_PATH" ]
  383.   then
  384.       echo "LD_LIBRARYN32_PATH=$LD_LIBRARYN32_PATH"
  385.   fi
  386.   if [ -n "$LD_LIBRARYN64_PATH" ]
  387.   then
  388.       echo "LD_LIBRARYN64_PATH=$LD_LIBRARYN64_PATH"
  389.   fi
  390.   if [ -n "$LD_LIBRARY_PATH_64" ]; then
  391.       echo "LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64"
  392.   fi
  393.   if [ -n "$DISPLAY" ]; then
  394.        echo "DISPLAY=$DISPLAY"
  395.   fi
  396.   if [ -n "$FONTCONFIG_PATH" ]; then
  397.     echo "FONTCONFIG_PATH=$FONTCONFIG_PATH"
  398.   fi
  399.   if [ -n "$XPSERVERLIST" ]; then
  400.        echo "XPSERVERLIST=$XPSERVERLIST"
  401.   fi
  402.   if [ -n "$MOZILLA_POSTSCRIPT_PRINTER_LIST" ]; then
  403.        echo "MOZILLA_POSTSCRIPT_PRINTER_LIST=$MOZILLA_POSTSCRIPT_PRINTER_LIST"
  404.   fi
  405.   echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
  406.   echo "     LIBRARY_PATH=$LIBRARY_PATH"
  407.   echo "       SHLIB_PATH=$SHLIB_PATH"
  408.   echo "          LIBPATH=$LIBPATH"
  409.   echo "       ADDON_PATH=$ADDON_PATH"
  410.   echo "      MOZ_PROGRAM=$MOZ_PROGRAM"
  411.   echo "      MOZ_TOOLKIT=$MOZ_TOOLKIT"
  412.   echo "        moz_debug=$moz_debug"
  413.   echo "     moz_debugger=$moz_debugger"
  414. fi
  415. #
  416. export MOZILLA_FIVE_HOME LD_LIBRARY_PATH
  417. export SHLIB_PATH LIBPATH LIBRARY_PATH ADDON_PATH DYLD_LIBRARY_PATH
  418.  
  419. if [ $moz_debug -eq 1 ]
  420. then
  421.     moz_debug_program ${1+"$@"}
  422. else
  423.     moz_run_program ${1+"$@"}
  424. fi
  425.  
  426. exit $exitcode
  427.